package com.mock.ems.config;

import com.jfinal.plugin.activerecord.Record;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class UserManager {

    private static Map<Long,Record> userMap = new ConcurrentHashMap<>();

    private static Long createTime = null;//初始化时间

    public static Record getUser(Long userId){
        return userMap.get(userId);
    }

    public static String getNickName(Long userId){
        Record user = userMap.get(userId);
        return user == null ? "" : user.getStr("nick_name");
    }

    public static void setUser(Record user){
        user.set("expiredTime", System.currentTimeMillis() / 1000);
        userMap.put(user.getLong("id"),user);
    }

    public static void setCreateTime(Long time){
        createTime = time;
    }

    public static Long getCreateTime(){
        return createTime;
    }

    public static void clearMap(){
        userMap.clear();
    }

    public static Map<Long,Record> getUserMap(){
        return userMap;
    }

    public static void remove(Long userId){
        userMap.remove(userId);
    }

}
